<template>
  <div>
    <el-card>
      <el-form inline>
        <el-form-item label="一级分类">
          <el-select
            placeholder="请选择"
            v-model="CategoryStore.c1Id"
            @change="handler"
            :disabled="isShow == 0 ? false : true"
          >
            <!-- lable即为展示的数据，value即为select收集的数据 -->
            <el-option
              v-for="c1 in CategoryStore.C1Arr"
              :key="c1.id"
              :label="c1.name"
              :value="c1.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="二级分类">
          <el-select
            placeholder="请选择"
            v-model="CategoryStore.c2Id"
            @change="handler1"
            :disabled="isShow == 0 ? false : true"
          >
            <el-option
              v-for="c2 in CategoryStore.C2Arr"
              :key="c2.id"
              :label="c2.name"
              :value="c2.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="三 级分类">
          <el-select
            placeholder="请选择"
            v-model="CategoryStore.c3Id"
            :disabled="isShow == 0 ? false : true"
          >
            <el-option
              v-for="c3 in CategoryStore.C3Arr"
              :key="c3.id"
              :label="c3.name"
              :value="c3.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script setup lang="ts">
//引入获取数据仓库
import useCategoryStore from "@/store/modules/Category";
//引入组合式api
import { onMounted } from "vue";
//获取仓库数据
let CategoryStore = useCategoryStore();
const getC1 = () => {
  CategoryStore.getC1();
};
//挂载时调用仓库中的getC1方法
onMounted(() => {
  getC1();
});
//一级分类菜单发生变化时触发
const handler = () => {
  //将上一次的数据清空
  CategoryStore.c2Id = "";
  CategoryStore.c3Id = "";
  //调用仓库中的getC2方法
  CategoryStore.getC2();
};
//二级分类菜单发生变化时触发
const handler1 = () => {
  //将上一次的数据清空
  CategoryStore.c3Id = "";
  //调用仓库中的getC2方法
  CategoryStore.getC3();
};
//接收父组件传来的数据
defineProps(["isShow"]);
</script>
